package kitwee.com.kanpad.bean;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import kitwee.com.kanpad.R;

/**
 * @author GanQuan
 * @date 2018/1/24
 * kitwee.com.kanpad.bean
 */

public class BomAdapter extends RecyclerView.Adapter<BomAdapter.MyHolder> {


    private List<ListDetailBean.ProductBOMVOListBean> bomList;
    private Context context;


    public BomAdapter(Context context,List<ListDetailBean.ProductBOMVOListBean> bomList) {
        this.bomList = bomList;
        this.context = context;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.bom_item, parent, false);
        MyHolder holder = new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyHolder holder, int position) {
        if(bomList.get(position).getMaterial_no()!=null){
            holder.bomNo.setText(""+ bomList.get(position).getMaterial_no());
        }else{
            holder.bomNo.setText("暂无");
        }
        holder.bomName.setText(""+bomList.get(position).getMaterial_name());
        holder.bomNorms.setText(""+bomList.get(position).getMaterial_specification_model());//规格
        holder.bomType.setText(""+bomList.get(position).getConsume_type_text());//物料类型
        holder.bomCount.setText(""+bomList.get(position).getConsume_amount());//消耗量
        holder.bomStock.setText(""+bomList.get(position).getMaterial_preparation_state_text());//备料状态
        holder.bomConsume.setText(""+bomList.get(position).getInitial_amount());//预计消耗量
        holder.actualConsume.setText(""+bomList.get(position).getConsume_amount());//实际消耗量
        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return bomList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.bom_no)
        TextView bomNo;
        @BindView(R.id.bom_name)
        TextView bomName;
        @BindView(R.id.bom_norms)
        TextView bomNorms;
        @BindView(R.id.bom_type)
        TextView bomType;
        @BindView(R.id.bom_count)
        TextView bomCount;
        @BindView(R.id.bom_stock)
        TextView bomStock;
        @BindView(R.id.bom_consume)
        TextView bomConsume;
        @BindView(R.id.actual_consume)
        TextView actualConsume;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }
}
